<?php defined("MAIN_DIR") or die("No direct access");

$vac_id = trim(strip_tags($route->getPath(4)));
$vacancy_res = mysql_query("select `vacancy`.*,`bank`.`name`,`bank`.`city_id` from `vacancy`,`bank` where `vacancy_id` = '$vac_id' and `bank`.`bank_id` = `vacancy`.`bank_id` limit 1");

if (mysql_num_rows($vacancy_res) == 0) {
	to("/$c_name/banks/vacancies");
}
$vacancy_row = mysql_fetch_array($vacancy_res);

$city_row = mysql_fetch_array(mysql_query("select * from `city` where `city_id` = '$vacancy_row[city_id]' limit 1"));
if ($_SESSION['city'] != $vacancy_row['city_id']) {
	to("/$city_row[path]/banks/vacancies/$vacancy_row[vacancy_id]");
}

$head_title = $vacancy_row['title']." - «Банки России»";

$category_query = "select `VC`.`category_id` as `id`,`VC`.`title` as `name`,COUNT(`vacancy`.`vacancy_id`) as `count` from `vacancy_categories` as `VC`,`vacancy` where `VC`.`category_id` = `vacancy`.`category_id` and `vacancy`.`bank_id` in (select `bank_id` from `bank` where `city_id` = '$_SESSION[city]') group by `id` order by `name`";
$category_res = mysql_query($category_query);
$category_count = mysql_num_rows($category_res);

$fresh_vac_query = "select `V`.`vacancy_id`,`V`.`title`,`V`.`salary`,`B`.`name`,`B`.`link` from `vacancy` as `V`,`bank` as `B` where `V`.`bank_id` = `B`.`bank_id` and `B`.`city_id` = '$_SESSION[city]' order by `V`.`vacancy_id` desc limit 4";
$fresh_vac_res = mysql_query($fresh_vac_query);
$fresh_vac_count = mysql_num_rows($fresh_vac_res);

require_once APP.HEADFILE;
?>
<script type="text/javascript" src="/files/js/bank_list.js"></script>
<h1><?php echo $vacancy_row['title']; ?></h1>
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 14px;">
	<tr>
		<td colspan="2" valign="top">
			<table width="100%" border="0" cellspacing="0" cellpadding="0" style="font-size: 14px;">
				<tr>
					<td width="35%">Город:</td>
					<td width="65%">
						<strong><?php
						$city_row = mysql_fetch_array(mysql_query("select `city_name` from `city` where `city_id` = '$vacancy_row[city_id]' limit 1"));
						echo $city_row['city_name'];
						?></strong>
					</td>
				</tr>
				<tr>
					<td class="vac_info_item">Банк:<br /></td>
					<td class="vac_info_item_grey"><?php echo $vacancy_row['name']; ?></td>
				</tr>
				<tr>
					<td class="vac_info_item">Оплата:<br /></td>
					<td class="vac_info_item_grey"><?php
						echo $vacancy_row['salary'] != 0 ? "от ".get_salary($vacancy_row['salary'])." руб." : "по договоренности"
					?></td>
				</tr>
				<tr>
					<td class="vac_info_item">Образование:<br /></td>
					<td class="vac_info_item_grey"><?php echo $education_array[$vacancy_row['education']]; ?></td>
				</tr><?php
				if ($vacancy_row['languages'] != "") {
					?><tr>
						<td class="vac_info_item">Иностранные языки:<br /></td>
						<td class="vac_info_item_grey"><?php echo $vacancy_row['languages']?></td>
					</tr><?php
				}
				if ($vacancy_row['phone'] != "") {
					?><tr>
						<td class="vac_info_item">Телефон:<br /></td>
						<td class="vac_info_item_grey"><?php echo $vacancy_row['phone']; ?></td>
					</tr><?php
				}
				if ($vacancy_row['fax'] != "")
				{
					?><tr>
						<td class="vac_info_item">Факс:</td>
						<td class="vac_info_item_grey"><?php echo $vacancy_row['fax']; ?></td>
					</tr><?php
				}
				if ($vacancy_row['email'] != "")
				{
					?><tr>
						<td class="vac_info_item">Электронный адрес:</td>
						<td class="vac_info_item_grey"><?php echo $vacancy_row['email']; ?></td>
					</tr><?php
				}
			?></table>
			<?php
			if ($vacancy_row['demands'] != "") {
				?><div class="vac_info_heading">Требования к кандидату</div>
				<div class="vac_info_text"><?php echo getRichText($vacancy_row['demands']); ?></div><?php
			}
			if ($vacancy_row['acting'] != "") {
				?><div class="vac_info_heading">Должностные обязанности</div>
				<div class="vac_info_text"><?php echo getRichText($vacancy_row['acting']); ?></div><?php
			}
			?>
		</td><?php
		if ($category_count > 0 || $fresh_vac_count > 0)
		{
			?><td width="312" align="left" valign="top">
				<div id="vac_items"><?php
					if ($fresh_vac_count > 0)
					{
						?><div class="vac_svezh_heading">Свежие вакансии</div><?php
						while($fresh_vac_row = mysql_fetch_array($fresh_vac_res))
						{
							?><div class="vac_item">
								<a href="<?php echo "/$c_name";?>/banks/vacancies/<?php echo $fresh_vac_row['vacancy_id']; ?>"><?php
								echo $fresh_vac_row['title']; ?></a> &nbsp;&nbsp;
								<span class="vac_bank"><a href="<?php echo "/$c_name";?>/banks/<?php echo $fresh_vac_row['link'].".html"; ?>"><?php
								echo $fresh_vac_row['name']; ?></a></span>
							</div>
							<div class="vac_salary"><?php
								echo $fresh_vac_row['salary'] != 0 ? "от ".get_salary($fresh_vac_row['salary'])." руб." : "по договоренности";
							?></div><?php
						}
					}
					if ($category_count > 0)
					{
						?><table cellpadding="8" cellspacing="0" style="margin-top:20px;font-size:14px">
							<tr>
								<td width="24%"><strong><a href="<?php echo "/$c_name";?>/banks/vacancies/?sort=list">Всего</a></strong></td>
								<td width="21%" align="left" valign="top">
									<strong><?php
									echo mysql_num_rows(mysql_query("select `vacancy_id` from `vacancy` where `bank_id` in (select `bank_id` from `bank` where `city_id` = '$_SESSION[city]')"));
									?></strong>
								</td>
							</tr><?php
							while ($category_row = mysql_fetch_array($category_res))
							{
								?><tr>
									<td>
										<a href="<?php echo "/$c_name";?>/banks/vacancies/?sort=list&category=<?php echo $category_row['id'];?>"><?php
										echo $category_row['name'];
										?></a>
									</td>
									<td width="21%" align="left" valign="top"><?php echo $category_row['count']; ?></td>
								</tr><?php
							}
						?></table><?php
					}
				?></div>
			</td><?php
		}
	?></tr>
</table>
</div>
<div class="inside_block">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr valign='top'>
			<td width="344" class="inside_info"><?php
				require_once APP."bank_list.php";
				require_once APP."currency_rates.php";
			?></td>
			<td width="646"><?php
				$info = mysql_fetch_array(mysql_query("select * from `info` where `info_id` = '4' limit 1"));
				$text = getRichText($info['text']);
				echo "<h2>$info[header]</h2>";
				echo "<p>$text</p>";
			?></td>
		</tr>
	</table>
</div>
<?php require_once APP.FOOTERFILE; ?>